package com.hcs.controller;

import com.hcs.comm.R;
import com.hcs.dto.DishUpdateDto;
import com.hcs.entity.Dish;
import com.hcs.service.IDishService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hcs
 * @since 2025-01-12 10:06
 */
@RestController
@RequestMapping("/dish")
@Tag(name = "DishController", description = "菜品管理")
@CrossOrigin
public class DishController {

    @Autowired
    IDishService dishService;

    //展示菜品数据
    @GetMapping("/getList")
    @Operation(summary = "展示菜品数据")
    public R<List<Dish>> getDishList() {
        return R.success(dishService.getAllDishes());
    }

    //根据名称查询
    @GetMapping("/listName")
    @Operation(summary = "根据名称查询")
    public R<List<Dish>> getDishListByName(@RequestParam String name) {
        return R.success(dishService.getDishListByName(name));
    }

    // 添加菜品
    @PostMapping
    @Operation(summary = "添加菜品")
    public R<?> addDish(@RequestBody Dish dish) {
        dishService.addDish(dish);
        return R.success();
    }

    // 更新菜品信息
    @PutMapping("/update")
    @Operation(summary = "更新菜品信息")
    public R<?> updateDish(@RequestBody Dish dish) {
        dishService.updateDish(dish);
        return R.success("修改成功");
    }

    // 删除菜品
    @Operation(summary = "删除菜品")
    @DeleteMapping("/{dishId}")
    public R<?> deleteDish(@PathVariable Long dishId) {
        dishService.deleteDish(dishId);
        return R.success("删除成功");
    }

    // 菜品上下架
//    @PatchMapping("/{dishId}/status")
//    @Operation(summary = "菜品上下架")
//    public R<?> changeDishStatus(@PathVariable Long dishId, @RequestParam String status) {
//        dishService.changeDishStatus(dishId, status);
//        return R.success();
//    }
}
